import 'package:decimal/decimal.dart';

/// @Title   图表的xy坐标数据
/// @Author: bryce
/// @CreateDate:  2023年09月12日10:58:18
class ChartXYData {
  // 限制的最大最小xy坐标
  final double _minX;
  final double _maxX;
  final double _minY;
  final double _maxY;

  // y的最大最小值（不等于上面的minY和maxY）
  final double _minValueY;
  final double _maxValueY;

  // xy轴的间隔值，（y间隔的是value值，x间隔的是日期）
  final double _yInterval;
  final int _xInterval;

  // Y轴的倍数（只有当y轴的：yInterval<1的时候，这个倍数才生效）
  final int yMultiplier;

  /// x轴的最小值（总轴）
  double get minX => _minX;
  /// x轴的最大值（总轴）
  double get maxX => _maxX;
  /// x轴的间隔值
  int get xInterval => _xInterval;

  /// Y轴的最小值 (总轴)
  double get minYChart => _minY;
  /// Y轴的真实最小值 (总轴)：因为Y轴可能会因值过小为了显示效果会翻十倍百倍
  double get minYReal => ((Decimal.tryParse('$_minY')??Decimal.zero)/Decimal.fromInt(yMultiplier)).toDouble();
  /// Y轴的最大值 (总轴)
  double get maxYChart => _maxY;
  /// Y轴的真实最大值 (总轴)：因为Y轴可能会因值过小为了显示效果会翻十倍百倍
  double get maxYReal => ((Decimal.tryParse('$_maxY')??Decimal.zero)/Decimal.fromInt(yMultiplier)).toDouble();

  /// Y轴的最小值 (数据点)
  double get minValueYChart => _minValueY;
  /// Y轴的真实最小值 (数据点)：因为Y轴可能会因值过小为了显示效果会翻十倍百倍
  double get minValueYReal => ((Decimal.tryParse('$_minValueY')??Decimal.zero)/Decimal.fromInt(yMultiplier)).toDouble();
  /// Y轴的最大值 (数据点)
  double get maxValueYChart => _maxValueY;
  /// Y轴的真实最大值 (数据点)：因为Y轴可能会因值过小为了显示效果会翻十倍百倍
  double get maxValueYReal => ((Decimal.tryParse('$_maxValueY')??Decimal.zero)/Decimal.fromInt(yMultiplier)).toDouble();
  /// Y轴的间隔值
  double get yIntervalChart => _yInterval;
  /// Y轴的真实间隔值：因为Y轴可能会因值过小为了显示效果会翻十倍百倍
  double get yIntervalReal => ((Decimal.tryParse('$_yInterval')??Decimal.zero)/Decimal.fromInt(yMultiplier)).toDouble();

  ChartXYData(
      {required double minX,
        required double maxX,
        required double minY,
        required double maxY,
        required double minValueY,
        required double maxValueY,
        required double yInterval,
        required int xInterval,
        this.yMultiplier = 1})
      :_minX = minX,
        _maxX = maxX,
        _minY = minY,
        _maxY = maxY,
        _minValueY = minValueY,
        _maxValueY = maxValueY,
        _yInterval = yInterval,
        _xInterval = xInterval;

  @override
  String toString() {
    return 'ChartXYData{_minX: $_minX, _maxX: $_maxX, _minY: $_minY, _maxY: $_maxY, _minValueY: $_minValueY, _maxValueY: $_maxValueY, _yInterval: $_yInterval, _xInterval: $_xInterval}';
  }
}